package cn.stylefeng.guns.sys.config;

import cn.hutool.extra.mail.MailAccount;
import cn.stylefeng.roses.email.modular.SimpleMailSender;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties({
        SysSmtpConfigProperty.class
})
public class CommonConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public SimpleMailSender sysMailSender(SysSmtpConfigProperty sysSmtpConfigProperty) {
        MailAccount mailAccount = new MailAccount();
        mailAccount.setHost(sysSmtpConfigProperty.getHost());
        mailAccount.setPort(sysSmtpConfigProperty.getPort());
        mailAccount.setAuth(sysSmtpConfigProperty.getAuth());
        mailAccount.setUser(sysSmtpConfigProperty.getUsername());
        mailAccount.setPass(sysSmtpConfigProperty.getPassword());
        mailAccount.setFrom(sysSmtpConfigProperty.getFrom());
        return new SimpleMailSender(mailAccount);
    }

}
